﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace FishSimulation.Model {
    public class World : ModelBase {
        #region Members
        private ObservableCollection<Actor> _Actors;
        private Pond _Pond;
        private long _Ticks;
        #endregion

        #region Properties
        public ObservableCollection<Actor> Actors {
            get
            {
                return _Actors;
            }
            set
            {
                if (_Actors != value)
                {
                    _Actors = value;
                    this.OnPropertyChanged("Actors");
                }
            }
        }
        
        public Pond Pond {
            get { return _Pond; }
            set
            {
                if (_Pond != value)
                {
                    _Pond = value;
                    this.OnPropertyChanged("Pond");
                }
            }
        }
        
        public long Ticks {
            get
            {
                return _Ticks;
            }
            set
            {
                if (_Ticks != value)
                {
                    _Ticks = value;
                    this.OnPropertyChanged("Ticks");
                }
            }
        }
        #endregion

        #region Constructors
        public World() {
        
        }
        #endregion

        #region Methods
        /// <summary>
        /// Gets all the actors in the given rectangle
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public List<Actor> GetByBounds(double x, double y, double width, double height) { 
            double x2 = x + width;
            double y2 = y + height;
            var q = 
                this.Actors.Where(obj => 
                    obj.X >= x && obj.X <= x2 &&
                    obj.Y >= y && obj.Y <= y2);
            return q.ToList();
        }

        public override string ToString() {
            return "World";
        }
        #endregion
    }
}
